package com.demo.gateway.filter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;

import com.demo.gateway.config.IgnoreUrlsConfig;

import reactor.core.publisher.Mono;

/**
 * 白名单路径访问时需要移除JWT请求头
 * @author yangjian
 * @version 创建时间：2022年2月25日 上午10:49:18
 */
@Component
public class IgnoreUrlsRemoveJwtFilter implements WebFilter {
    @Autowired
    private IgnoreUrlsConfig ignoreUrlsConfig;
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
//        ServerHttpRequest request = exchange.getRequest();
//        URI uri = request.getURI();
//        PathMatcher pathMatcher = new AntPathMatcher();
//        //白名单路径移除JWT请求头
//        List<String> ignoreUrls = ignoreUrlsConfig.getUrls();
//        for (String ignoreUrl : ignoreUrls) {
//            if (pathMatcher.match(ignoreUrl, uri.getPath())) {
//                request = exchange.getRequest().mutate().header("Authorization", "").build();
//                exchange = exchange.mutate().request(request).build();
//                return chain.filter(exchange);
//            }
//        }
        return chain.filter(exchange);
    }
}
